local PLANT_DEFS           = require("prefabs/farm_plant_defs").PLANT_DEFS
MY_PLANT_TABLE             = { "tf_orange", "tf_cabbage", "tf_green_pepper", "tf_strawberry" }

PLANT_DEFS.tf_orange       = {}
PLANT_DEFS.tf_cabbage      = {}
PLANT_DEFS.tf_green_pepper = {}
PLANT_DEFS.tf_strawberry   = {}

local function MakeGrowTimes(germination_min, germination_max, full_grow_min, full_grow_max)
    local grow_time     = {}

    -- 发芽时间
    grow_time.seed      = { germination_min, germination_max }

    -- 成长时间
    grow_time.sprout    = { full_grow_min * 0.5, full_grow_max * 0.5 }
    grow_time.small     = { full_grow_min * 0.3, full_grow_max * 0.3 }
    grow_time.med       = { full_grow_min * 0.2, full_grow_max * 0.2 }

    -- 可收获的腐烂时间
    grow_time.full      = 4 * TUNING.TOTAL_DAY_TIME
    grow_time.oversized = 6 * TUNING.TOTAL_DAY_TIME
    -- 非巨大植株腐烂后回发芽阶段的时间
    grow_time.regrow    = { 4 * TUNING.TOTAL_DAY_TIME, 5 * TUNING.TOTAL_DAY_TIME }

    return grow_time
end

--                                                        germination min / max						  full grow time min / max
PLANT_DEFS.tf_orange.grow_time                  = MakeGrowTimes(12 * TUNING.SEG_TIME, 16 * TUNING.SEG_TIME, 4 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME)
PLANT_DEFS.tf_cabbage.grow_time                 = MakeGrowTimes(12 * TUNING.SEG_TIME, 16 * TUNING.SEG_TIME, 4 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME)
PLANT_DEFS.tf_green_pepper.grow_time            = MakeGrowTimes(12 * TUNING.SEG_TIME, 16 * TUNING.SEG_TIME, 4 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME)
PLANT_DEFS.tf_strawberry.grow_time              = MakeGrowTimes(12 * TUNING.SEG_TIME, 16 * TUNING.SEG_TIME, 4 * TUNING.TOTAL_DAY_TIME, 7 * TUNING.TOTAL_DAY_TIME)

-- 吸水
local drink_low                                 = TUNING.FARM_PLANT_DRINK_LOW
local drink_med                                 = TUNING.FARM_PLANT_DRINK_MED
local drink_high                                = TUNING.FARM_PLANT_DRINK_HIGH

PLANT_DEFS.tf_orange.moisture                   = { drink_rate = drink_low, min_percent = TUNING.FARM_PLANT_DROUGHT_TOLERANCE }
PLANT_DEFS.tf_cabbage.moisture                  = { drink_rate = drink_med, min_percent = TUNING.FARM_PLANT_DROUGHT_TOLERANCE }
PLANT_DEFS.tf_green_pepper.moisture             = { drink_rate = drink_low, min_percent = TUNING.FARM_PLANT_DROUGHT_TOLERANCE }
PLANT_DEFS.tf_strawberry.moisture               = { drink_rate = drink_low, min_percent = TUNING.FARM_PLANT_DROUGHT_TOLERANCE }

-- 季节偏好
PLANT_DEFS.tf_orange.good_seasons               = { autumn = true, spring = true, summer = true }
PLANT_DEFS.tf_cabbage.good_seasons              = { autumn = true, spring = true }
PLANT_DEFS.tf_green_pepper.good_seasons         = { autumn = true, spring = true }
PLANT_DEFS.tf_strawberry.good_seasons           = { spring = true, summer = true }

-- 三种养分
local S                                         = TUNING.FARM_PLANT_CONSUME_NUTRIENT_LOW
local M                                         = TUNING.FARM_PLANT_CONSUME_NUTRIENT_MED
local L                                         = TUNING.FARM_PLANT_CONSUME_NUTRIENT_HIGH

PLANT_DEFS.tf_orange.nutrient_consumption       = { 0, M, M }
PLANT_DEFS.tf_cabbage.nutrient_consumption      = { 0, M, 0 }
PLANT_DEFS.tf_green_pepper.nutrient_consumption = { M, 0, 0 }
PLANT_DEFS.tf_strawberry.nutrient_consumption   = { M, M, 0 }

-- 营养恢复
for veggie, data in pairs(PLANT_DEFS) do
    local my_plant = table.contains(MY_PLANT_TABLE, veggie)
    if my_plant then
        data.nutrient_restoration = {}
        for i = 1, #data.nutrient_consumption do
            data.nutrient_restoration[i] = data.nutrient_consumption[i] == 0 or nil
        end
    end
end

-- 杂草??
PLANT_DEFS.tf_orange.max_killjoys_tolerance       = TUNING.FARM_PLANT_KILLJOY_TOLERANCE
PLANT_DEFS.tf_cabbage.max_killjoys_tolerance      = TUNING.FARM_PLANT_KILLJOY_TOLERANCE
PLANT_DEFS.tf_green_pepper.max_killjoys_tolerance = TUNING.FARM_PLANT_KILLJOY_TOLERANCE
PLANT_DEFS.tf_strawberry.max_killjoys_tolerance   = TUNING.FARM_PLANT_KILLJOY_TOLERANCE

-- 杂项

-- 重量区间
PLANT_DEFS.tf_orange.weight_data                  = { 340.20, 582.64, .48 }
PLANT_DEFS.tf_cabbage.weight_data                 = { 361.51, 506.04, .28 }
PLANT_DEFS.tf_green_pepper.weight_data            = { 368.55, 486.32, .11 }
PLANT_DEFS.tf_strawberry.weight_data              = { 384.59, 662.77, .18 }

PLANT_DEFS.tf_orange.pictureframeanim             = { anim = "emoteXL_loop_dance7", time = 37 * FRAMES }
PLANT_DEFS.tf_cabbage.pictureframeanim            = { anim = "emote_happycheer", time = 12 * FRAMES }
PLANT_DEFS.tf_green_pepper.pictureframeanim       = { anim = "emote_swoon", time = 37 * FRAMES }
PLANT_DEFS.tf_strawberry.pictureframeanim         = { anim = "emoteXL_loop_dance0", time = 7 * FRAMES }

-- 声音
PLANT_DEFS.tf_orange.sounds                       = PLANT_DEFS.potato.sounds
PLANT_DEFS.tf_cabbage.sounds                      = PLANT_DEFS.potato.sounds
PLANT_DEFS.tf_green_pepper.sounds                 = PLANT_DEFS.pepper.sounds
PLANT_DEFS.tf_strawberry.sounds                   = PLANT_DEFS.potato.sounds

------------------------------------------------
for veggie, data in pairs(PLANT_DEFS) do
    local my_plant = table.contains(MY_PLANT_TABLE, veggie)
    if my_plant then
        data.prefab = "farm_plant_" .. veggie

        if data.bank == nil then data.bank = "farm_plant_" .. veggie end
        if data.build == nil then data.build = "farm_plant_" .. veggie end

        data.product = veggie
        data.product_oversized = veggie .. "_oversized"
        data.seed = veggie .. "_seeds"
        data.plant_type_tag = "farm_plant_" .. veggie -- note: this is used for pollin_sources stress

        data.loot_oversized_rot = { "spoiled_food", "spoiled_food", "spoiled_food", data.seed, "fruitfly", "fruitfly" }

        -- 所有农作物都是相同的家庭数量要求,或许你可以搞特殊
        if data.family_min_count == nil then data.family_min_count = TUNING.FARM_PLANT_SAME_FAMILY_MIN end
        if data.family_check_dist == nil then data.family_check_dist = TUNING.FARM_PLANT_SAME_FAMILY_RADIUS end

        if data.stage_netvar == nil then
            data.stage_netvar = net_tinybyte
        end

        if data.plantregistryinfo == nil then
            data.plantregistryinfo = {
                {
                    text = "seed",
                    anim = "crop_seed",
                    grow_anim = "grow_seed",
                    learnseed = true,
                    growing = true,
                },
                {
                    text = "sprout",
                    anim = "crop_sprout",
                    grow_anim = "grow_sprout",
                    growing = true,
                },
                {
                    text = "small",
                    anim = "crop_small",
                    grow_anim = "grow_small",
                    growing = true,
                },
                {
                    text = "medium",
                    anim = "crop_med",
                    grow_anim = "grow_med",
                    growing = true,
                },
                {
                    text = "grown",
                    anim = "crop_full",
                    grow_anim = "grow_full",
                    revealplantname = true,
                    fullgrown = true,
                },
                {
                    text = "oversized",
                    anim = "crop_oversized",
                    grow_anim = "grow_oversized",
                    revealplantname = true,
                    fullgrown = true,
                    hidden = true,
                },
                {
                    text = "rotting",
                    anim = "crop_rot",
                    grow_anim = "grow_rot",
                    stagepriority = -100,
                    is_rotten = true,
                    hidden = true,
                },
                {
                    text = "oversized_rotting",
                    anim = "crop_rot_oversized",
                    grow_anim = "grow_rot_oversized",
                    stagepriority = -100,
                    is_rotten = true,
                    hidden = true,
                },
            }
        end
        if data.plantregistrywidget == nil then
            data.plantregistrywidget = "widgets/redux/farmplantpage"
        end
        if data.plantregistrysummarywidget == nil then
            data.plantregistrysummarywidget = "widgets/redux/farmplantsummarywidget"
        end
        if data.pictureframeanim == nil then
            data.pictureframeanim = { anim = "emoteXL_happycheer", time = 0.5 }
        end
    end
end
